package com.zhangxu.microservice.employee.dao.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhangxu.microservice.employee.dao.condition.EmployeeCondition;
import com.zhangxu.microservice.employee.dao.entity.EmployeeDO;
import com.zhangxu.microservice.employee.dao.mapper.EmployeeMapper;
import com.zhangxu.microservice.employee.dao.service.EmployeeDao;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

@Repository
public class EmployeeDaoImpl extends ServiceImpl<EmployeeMapper, EmployeeDO> implements EmployeeDao {


    @Override
    public List<EmployeeDO> listByIds(Collection<? extends Serializable> idList) {
        return this.lambdaQuery()
                .in(EmployeeDO::getId, idList)
                .eq(EmployeeDO::getDeleteTime, 0L)
                .list();
    }

    @Override
    public EmployeeDO getByAccount(String account) {
        return this.lambdaQuery()
                .eq(EmployeeDO::getAccount, account)
                .eq(EmployeeDO::getDeleteTime, 0L)
                .one();
    }

    @Override
    public EmployeeDO getById(Serializable id) {
        return this.lambdaQuery()
                .eq(EmployeeDO::getId, id)
                .eq(EmployeeDO::getDeleteTime, 0L)
                .one();
    }

    @Override
    public IPage<EmployeeDO> page(EmployeeCondition condition) {
        condition.checkPage();
        return this.lambdaQuery()
                .like(StrUtil.isNotBlank(condition.getAccount()), EmployeeDO::getAccount, condition.getAccount())
                .like(StrUtil.isNotBlank(condition.getName()), EmployeeDO::getName, condition.getName())
                .eq(EmployeeDO::getDeleteTime, 0L)
                .page(condition.getIpage());
    }
}
